﻿@model WebUI.Models.QizSession
@{
    var PreviewOnly = (bool)TempData["PreviewOnly"];
    var skipSub = (bool)TempData["skipSub"];

    var ClosedDateMin = DateTime.Now;
    var ClosedDateMax = DateTime.Now;

    if (PreviewOnly && Model.Timemark > DateTime.MinValue)
    {

        ClosedDateMin = Model.Timemark.AddMonths(-12);
        ClosedDateMax = Model.Timemark.AddMonths(6);
    }    
}
@if (PreviewOnly && !skipSub && Model.QizSubject.SubQizSubjects.Count > 0)
{
    foreach (var subSubj in Model.QizSubject.SubQizSubjects.OrderByDescending(v => v.SortIdx))
    {
        var selSubSesID = string.Empty;

    <a name="Subject_@(subSubj.ID)" id="Subject_@(subSubj.ID)"></a>

    <fieldset>
        <legend>
            <div class="catalog-title">@subSubj.Title</div>
        </legend>
        <div id="SubSubjTabs@(subSubj.ID)">
            @{
        var subsesquery = subSubj.QizSessions.Where(v => v.RecuperID == Model.RecuperID && v.Timemark <= Model.Timemark).OrderByDescending(v => v.Timemark).Take(9).Union(
                        subSubj.QizSessions.Where(v => v.RecuperID == Model.RecuperID && v.Timemark > Model.Timemark).OrderBy(v => v.Timemark).Take(3)
                        ).OrderBy(v => v.Timemark).ToList();
            }
            @if (subsesquery.Count == 0)
            {
                <div>
                    没有 @subSubj.Title 数据</div>
            }
            else
            {
                <ul>
                    @foreach (var subSes in subsesquery)
                    {

                        <li id="subTab@(subSes.ID)">@Html.ActionLink(subSes.Timemark.ToString("[yyyy-MM-dd]"), "QizSessionEdit", new { ID = subSes.ID, PreviewOnly = true, SkipSub = true, IsView = false })</li>
                        if (subSes.Timemark.Date == Model.Timemark.Date)
                        {
                            selSubSesID = subSes.ID;
                        }
                    }
                </ul>
                <script type="text/javascript">
                    $(function () {
                        $("#SubSubjTabs@(subSubj.ID)").tabs({
                            collapsible: true,
                            beforeActivate: function (event, ui) {
                                ui.oldPanel.html("");
                                ui.newPanel.html("正在载入,请稍等...");
                            },
                            beforeLoad: function (event, ui) {
                                ui.jqXHR.error(function () {
                                    ui.panel.html("载入失败，刷新页面可能解决问题，如果仍然失败，请联系管理员。");
                                });
                            }
                        });
                        @if (selSubSesID != string.Empty)
                        {
                            @:$('#subTab@(selSubSesID) a').click();
                        }                                        
                    });
                </script>
       
            }
        </div>
        <div>
            <a href="#" onclick="$('#SubSubjTabs@(subSubj.ID)').toggle(1000); return false;">[+展开/-收起]</a></div>
    </fieldset>           
    }

}